import adraw.*;
import geometry.*;
import tester.*;
import java.util.*;
import colors.*;

/**
 * World Class
 * @author Ryan & Adam
 */
class WholeGameWorld extends World{
  Mfmwg genie;
  ILoS stars;
  
  /**
   * Constructor
   * @param genie The Genie...
   * @param stars The Stars...
   */
  WholeGameWorld(Mfmwg genie, ILoS stars) {
    this.genie = genie;
    this.stars = stars;
  }
  /*
   * TEMPLATE:
   * FIELDS:
   * ... this.genie ...            --Mfmwg
   *
   * METHODS:
   * ... this.onKeyEvent() ...      -- void
   * ... this.onTick) ...           -- void
   * ... this.draw() ...            -- void
   *
   * METHODS FOR FIELDS:
   * ... this.stars.drawStars(Canvas c) ...  -- void
   * ... this.stars.onTick(Mfmwg m) ...      -- void
   * ... this.stars.foundStar(Mfmwg m) ...   -- boolean
   * ... this.stars.caughtStar(Mfmwg m) ...  -- void
   * ... this.genie.drawMfmwg(Canvas c) ...  -- void
   * ... this.genie.catchStar() ...          -- void
   * ... this.genie.onKeyEvent(String ke) ...-- void
   * ... this.genie.onTick() ...             -- void
   */ 
  
  /* (non-Javadoc)
   * Produce a walker moved in the direction given by the key
   * @see adraw.World#onKeyEvent(java.lang.String)
   */
  @Override public void onKeyEvent(String ke){
    if (this.stars.foundStar(this.genie)){
      this.genie.catchStar(this.stars.caughtStar(this.genie)).onKeyEvent(ke);
    } else { 
      this.genie.onKeyEvent(ke);
    }
  }
  
  /* (non-Javadoc)
   * Ticks the world once and updates all things.
   * @see adraw.World#onTick()
   */
  public void onTick(){
    if(this.genie.fuel <=0) { 
      endOfWorld("you're out of fuel, fool!");
    } else {
      this.genie.onTick();
      this.stars.onTick(this.genie); 
    }
  }
  
  /* (non-Javadoc)
   * Draws the whole wide world.
   * @see adraw.World#draw()
   */
  public void draw(){
    this.genie.drawMfmwg(this.theCanvas);
    this.stars.drawStars(this.theCanvas);
    
  }
  
  //  public static void main(String[] argv){
  //    // construct an instance of a TimerWorld
  //    Examples w = new Examples();
  //    // and run the TimerWorld
  //    w.go();
  //  }
}